package com.sinosoft.yuebao.servicebus.dto.common;

import com.sinosoft.kuafu.core.util.DateUtils;
import lombok.Data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author handong
 */
@Data
public class YueBaoResponse {

    /**
     * 对接方id
     */
    private String appId;

    /**
     * 对接方方法
     */
    private String method;

    /**
     *签名
     */
    private String sign;

    /**
     * 返回时间
     */
    private String timestamp;

    /**
     * 请求id
     */
    private String requestId;

    /**
     * 返回代码
     */
    private String code;

    /**
     * 返回内容
     */
    private String message;

    /**
     * 返回报文
     */
    private String content;


    /**
     * 失败的构造
     * @param yueBaoRequest
     * @param responseMessage
     * @return
     */
    public static YueBaoResponse error(YueBaoRequest yueBaoRequest, String responseMessage) {
        YueBaoResponse response  = new YueBaoResponse();
        response.setAppId(yueBaoRequest.getAppId());
        response.setMethod(yueBaoRequest.getMethod());
        response.setRequestId(yueBaoRequest.getRequestId());
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        response.setTimestamp(sf.format(new Date()));
        response.setCode("00");
        response.setMessage(responseMessage);
        return response;
    }


    /**
     * 成功的构造
     * @param yueBaoRequest
     * @param content
     * @return
     */
    public static YueBaoResponse success(YueBaoRequest yueBaoRequest, String content) {
        YueBaoResponse response  = new YueBaoResponse();
        response.setAppId(yueBaoRequest.getAppId());
        response.setMethod(yueBaoRequest.getMethod());
        response.setRequestId(yueBaoRequest.getRequestId());
        response.setCode("01");
        response.setMessage("请求成功");
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        response.setTimestamp(sf.format(new Date()));
        response.setContent(content);
        return response;
    }


}
